
rem
bbdoc: Position component, also handles render tweening.
end rem
Type TPositionComponent Extends TComponent {expose hidefields}
	
	Field _renderPosition:TVector2D
	Field _position:TVector2D
	Field _previousPosition:TVector2D
	

	Method New() {hidden}
		_position = New TVector2D
		_renderPosition = New TVector2D
		_previousPosition = New TVector2D
	End Method
	
	
	Rem
	bbdoc: Create function.
	endrem
	Function Create:TPositionComponent(x:Float, y:Float) {hidden}
		Local t:TPositionComponent = New TPositionComponent
		t.Reset(x, y)
		Return t
	End Function
	
	
	Rem
	bbdoc: Sets the render position according to specified tween value.
	about: Call this in your render system before rendering.
	endrem	
	Method Interpolate(tween:Double) {hidden}
		_renderPosition.SetX( Double(_position.GetX()) * tween + .. 
			Double(_previousPosition.GetX()) * (1.0:Double - tween) )
		_renderPosition.SetY( Double(_position.GetY()) * tween + .. 
			Double(_previousPosition.GetY()) * (1.0:Double - tween) )
	End Method
	

	'called by the movement system.
	Method Update() {hidden}
		_previousPosition.Set( _position.GetX(), _position.GetY())
	End Method
	
	
	rem
	bbdoc: Returns true if this point has changed since last update.
	endrem
	Method Changed:Int()
		Return Not _position.IsSame(_previousPosition)
	End Method
	
	
	Method Reset(x:Float, y:Float)
		_renderPosition.Set(x, y)
		_position.Set(x,y)
		_previousPosition.Set(x, y)
	End Method
	
		
	Method Set(x:Float, y:Float)
		_position.Set(x,y)
	End Method
	
	Method GetX:Float()
		Return _position.GetX()
	End Method
	
	Method GetY:Float()
		Return _position.GetY()
	End Method
	
	Method SetX(x:Float)
		_position.SetX(x)
	End Method
	
	Method SetY(y:Float)
		_position.SetY(y)
	End Method
	
	Method Get:TVector2D()
		Return _position
	End Method
	
	Method Add(x:Float, y:Float)
		_position.Add(x,y)
	End Method

	Method AddX(x:Float)
		_position.AddX(x)
	End Method
	
	Method AddY(y:Float)
		_position.AddY(y)
	End Method
		
	Method AddV(v:TVector2D)
		_position.AddV(v)
	End Method	
		
	Method GetRenderX:Float()
		Return _renderPosition.GetX()
	End Method
	
	Method GetRenderY:Float()
		Return _renderPosition.GetY()
	End Method		

	Method GetDistanceTo:Float(p:TPositionComponent)
		Return _position.Distance(p.Get())
	End Method	
	
End Type

